import { JXDef } from "../../../conventions/JXCommon";
import { GStatic } from "../../../Core/Manager/DataPool";
import GameMgr from "../../Logic/GameMgr";

const { ccclass } = cc._decorator;
@ccclass
export class SEquipData extends GStatic {
    public parse(obj: any): boolean {
        for (let i = 0; i < obj.data.length; i++) {
            let raw = GStatic.addonRaw<SEquipDataRaw>(obj.data[i]);
            this._data.set(raw.id, raw);
        }
        return true;
    }

    /**通过职业拿装备 */
    public getEquipByEquip(type: number, select: number): SEquipDataRaw[] {
        let arr = [];
        this._data.forEach((v: SEquipDataRaw) => {
            if ((v.job === type && v.lv <= select) || (v.job === 0 && v.lv === select)) {
                let quality: [] = GameMgr.systemConfig.value(JXDef.SYS_CONFIG_KEY.quality);
                quality.forEach((value) => {
                    if (v.trait == value) {
                        arr.push(v);
                    }
                })
            }
        })
        return arr;
    }

    /**
     * 
     * @param type 职业类型
     * @param heroid 英雄id
     * @param lv 穿戴等级
     * @param trait 品质
     */
    public getJackpot(type: number, heroid: number, minlv: number, maxlv: number, trait: number, seat: number) {
        let arr = [];


        this._data.forEach((v: SEquipDataRaw) => {
            v.target.forEach((h) => {
                if (h == heroid || h == 0) {
                    if ((v.trait == trait && v.lv >= minlv && v.lv <= maxlv && v.job == type) || (v.trait == trait && v.lv >= minlv && v.lv <= maxlv && v.job == 0)) {
                        arr.push(v);
                    }
                }
            })
        })
        if (arr.length == 0) {
            // console.log("需要向下寻找");
        }
        return arr;
    }
}